package ca.uwindsor.cs.deepweb.estimation.method.border;

import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;

import ca.uwindsor.cs.deepweb.estimation.RandomWordSelector;
import ca.uwindsor.cs.deepweb.estimation.experiment.service.QueryService;

public class QueryRunnerWords {

	/**
	 * @param args
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException {
		if(args.length!=5){
			System.out.println("java QueryRunnerWords wordlist.txt index outputfile");
			System.exit(-1);
		}
		ArrayList<String> words;
		RandomWordSelector selector = new RandomWordSelector(args[0], "UTF-8");
		words = selector.getWordList();
		String[] wl = words.toArray(new String[words.size()]);
		QueryService qs = new QueryService(args[1], new Integer(args[3]), wl, new Integer(args[4]),
				null, false);

		try {
			qs.setStepSize(new Integer(args[4]));
			// qs.setOuputDocumentUniqueTerms(indexdir)
			qs.setOutputDocumentCaptureFrequencyDistribution(false);
			// qs.setOuputDocumentUniqueAndTotalTerms(
			// "F:\\DocumentNumberofUniqueTotalTermsIndex\\GOV2_doc_terms_unique_total\\0"
			// );
			qs.setOutputORmethodResult(false);
			qs.setOutputDocumentFrequency(false);
			qs.setOutputDocumentSize(false);
			qs.setOutputDocumentSizeDistribution(false);
			qs.setOutputTermWeightandNumberofDocument(true);
			qs.setOutputTermWeightDistribution(false);
			qs.setOutputDocumentWeight(false);
			String result = qs.goQuery();

			System.out.println(result);
			FileOutputStream fp;
			fp = new FileOutputStream(args[2]);
			fp.write(result.getBytes("UTF-8"));
			fp.flush();
			fp.close();
		} catch (Exception e) {
			e.printStackTrace();
		}

	}

}
